package mutil.thread;

/**
 * Created by luoqifei on 17-7-12.
 */
public class JionTest {
    //join(), main thread must wait the Thread run finish to continue
    //join(time).main thread wait time,after time,main Thread run continue
    public static void main(String args[]){
        final Thread thread = new Thread(new Runnable() {
            public void run() {
                try {
                    System.out.println("start to sleep");
                    Thread.sleep(2000);
                    System.out.println("finish sleep");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        try {
            thread.join(1000);
            if(thread.isAlive()){
                System.out.println("thread is alive,wait for finish");
                thread.join();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main thread had wait jion finish ");

    }
}
